package com.isoft.service.impl;

import com.isoft.service.DfmeGtlsService;
import com.isoft.service.XmlFileHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.nio.file.Path;
import java.nio.file.Files;

@Component
public class DfmeGtlsFileHandler implements XmlFileHandler {

    @Autowired
    private DfmeGtlsService dfmeGtlsService;

    @Override
    public boolean supports(Path filePath) {
        String fileName = filePath.getFileName().toString();
        if (fileName.contains("GTLS")) return true;
        try {
            String content = Files.readString(filePath);
            return content.contains("<STYP>GTLS</STYP>");
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public String handle(Path filePath) {
        try {
            String xmlContent = Files.readString(filePath);
            return dfmeGtlsService.parseAndSave(xmlContent);
        } catch (Exception e) {
            throw new RuntimeException("处理DFME-GTLS文件失败: " + filePath, e);
        }
    }
} 